package com.simon.train.business.controller.admin;


import com.simon.train.business.dto.TrainQueryDto;
import com.simon.train.business.dto.TrainSaveDto;
import com.simon.train.business.service.TrainSeatService;
import com.simon.train.business.service.TrainService;
import com.simon.train.business.vo.DailyTrainQueryVO;
import com.simon.train.business.vo.TrainQueryVO;
import com.simon.train.common.Result.Result;
import com.simon.train.common.vo.PageVO;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/train")
public class TrainAdminController {

    @Resource
    private TrainService trainService;

    @Resource
    private TrainSeatService trainSeatService;

    @PostMapping("/save")
    public Result<Object> SaveTrain(@Valid @RequestBody TrainSaveDto trainSaveDto){
        trainService.SaveTrain(trainSaveDto);
        return new Result<>();
    }

    @GetMapping("/queryList")
    public Result<PageVO<TrainQueryVO>> TrainQueryList(@Valid TrainQueryDto trainQueryDto){
         /**
         * businessId通过线程变量获取 从而不需要由前端传入 保证了效率和安全性
         */
        PageVO<TrainQueryVO> lists = trainService.QueryTrainList(trainQueryDto);
        return new Result<>(lists);
    }

    /**
     * 基础数据端查询全部的列车信息
     * @return
     */
    @GetMapping("/queryAll")
    public Result<List<TrainQueryVO>> TrainQueryList(){
        List<TrainQueryVO> lists = trainService.QueryTrainAll();
        return new Result<>(lists);
    }

    /**
     * 每日数据端查询全部的列车信息
     * @return
     */
    @GetMapping("/queryDailyAll")
    public Result<List<DailyTrainQueryVO>> TrainDailyQueryList(){
        List<DailyTrainQueryVO> lists = trainService.QueryTrainDailyAll();
        return new Result<>(lists);
    }

    @DeleteMapping("/delete/{id}")
    public Result<Object> DeleteTrain(@PathVariable("id") Long id){
        trainService.deleteTrain(id);
        return new Result<>();
    }


    /**
     * 根据列车的编号 直接去通过生成器生成完整的座位
     * @param trainCode
     * @return
     */
    @GetMapping("/genTrainCode/{trainCode}")
    public Result<Object> GenerateTrainCode(@PathVariable("trainCode") String trainCode){
        trainSeatService.GenerateTrainSeat(trainCode);
        return new Result<>();
    }

}
